<?php
session_start();
include('lib/lib.php');
include('connado.php');
//include('authen.php');
header("Content-type: text/html; charset=utf-8");
$logfile = PAHTLOG."ajax_cmdmsu-" . date("Y-m-d") . ".log";


$msu_name = $_REQUEST['msu_name'];
$province_id = $_REQUEST['province_id'];
$action = $_REQUEST['action'];

writelog($logfile, "msu_name num     : " . $msu_name);
writelog($logfile, "province_id      : " . $province_id);
writelog($logfile, "action   : " . $action);

if($action == "add"){
	$sql = "insert into ncen(ncen_name, province_id)values(?, ?)";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($msu_name, $province_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "add ncen success!");
	}else{
		writelog($logfile, "add ncen error!");
	}
}else if($action == "del"){
	$sql = "delete from ncen where ncen_name=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($msu_name);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "delete ncen success!");
	}else{
		writelog($logfile, "delete ncen error!");
	}
}else if($action == "edit"){
	$sql = "update ncen set ncen_name =?, province_id=? where ncen_name=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($msu_name, $province_id, $msu_name);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "update ncen success!");
	}else{
		writelog($logfile, "update ncen error!");
	}
	
}


writelog($logfile, "reply : OK");
writelog($logfile, "-------------------------------------------------- ");
echo viewMsu($db);

?>

